<?php

/**
 * Plugin manager for front controller
 *
 * @package Rapide_Controller
 */
final class Rapide_Controller_Front_Plugin_Manager implements Rapide_Controller_Front_Plugin_Manager_Interface
{
	private $_aPlugins = array();

	/**
	 * Register plugin
	 *
	 * @param Rapide_Controller_Front_Plugin_Interface $oPlugin
	 */
	public function register(Rapide_Controller_Front_Plugin_Interface $oPlugin)
	{
		$this->_aPlugins[] = $oPlugin;
	}

	/**
	 * Execute pre dispatch loop plugins
	 *
	 * @param Rapide_Dispatcher_Token_Interface $oToken
	 * @return Rapide_Dispatcher_Token
	 */
	public function preDispatchLoop(Rapide_Dispatcher_Token_Interface $oToken)
	{
		foreach($this->_aPlugins as $oPlugin)
			$oToken = $oPlugin->preDispatchLoop($oToken);

		return $oToken;
	}

	/**
	 * Execute post dispatch loop plugins
	 *
	 * @param Rapide_Dispatcher_Token_Interface $oToken
	 * @return Rapide_Dispatcher_Token_Interface
	 */
	public function postDispatchLoop(Rapide_Dispatcher_Token_Interface $oToken)
	{
		foreach($this->_aPlugins as $oPlugin)
			$oToken = $oPlugin->postDispatchLoop($oToken);

		return $oToken;
	}

	/**
	 * Execute pre execution plugins
	 *
	 * @param Rapide_Dispatcher_Token_Interface $oToken
	 * @return Rapide_Dispatcher_Token_Interface
	 */
	public function preExecution(Rapide_Dispatcher_Token_Interface $oToken)
	{
		foreach($this->_aPlugins as $oPlugin)
			$oToken = $oPlugin->preExecution($oToken);

		return $oToken;
	}

	/**
	 * Execute post execution plugins
	 *
	 * @param Rapide_Dispatcher_Token_Interface $oToken
	 * @return Rapide_Dispatcher_Token_Interface
	 */
	public function postExecution(Rapide_Dispatcher_Token_Interface $oToken)
	{
		foreach($this->_aPlugins as $oPlugin)
			$oToken = $oPlugin->postExecution($oToken);

		return $oToken;
	}
}

?>